﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace CJJCH.Web
{
    public partial class SciencTechExpansion : System.Web.UI.Page
    {
        CJJCH.BLL.T_NET_MenuSecond bll_second = new CJJCH.BLL.T_NET_MenuSecond();
        CJJCH.BLL.T_NET_News bll_news = new CJJCH.BLL.T_NET_News();
        CJJCH.BLL.T_NET_Consulting bll_cons = new CJJCH.BLL.T_NET_Consulting();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitRequest();
            }
        }

        private void InitRequest()
        {
            if (Request.QueryString["secondid"] != null && LTP.Common.CheckInput.CheckDigit(Request.QueryString["secondid"].ToString()))
            {
                this.lblSecondid.Text = Request.QueryString["secondid"].ToString();
            }
            else
            {
                this.lblSecondid.Text = bll_second.GetMinModel(5).ID.ToString();
            }

            if (Request.QueryString["name"] != null)
            {

                this.lblType.Text = Request.QueryString["name"].ToString();
            }
            else
            {
                this.lblType.Text = "政策法规";
            }
            if (Request.QueryString["MID"] != null && LTP.Common.CheckInput.CheckDigit(Request.QueryString["MID"].ToString()))
            {
                this.lblMID.Text = Request.QueryString["MID"].ToString();
            }
            else
            {
                this.lblMID.Text = "2";
            }
            if (Request.QueryString["curpage"] != null && LTP.Common.CheckInput.CheckDigit(Request.QueryString["curpage"].Trim()))
            {
                AspNetPager1.CurrentPageIndex = System.Convert.ToInt32(Request.QueryString["curpage"].Trim());
                AspNetPager2.CurrentPageIndex = AspNetPager1.CurrentPageIndex;
            }
            else
            {
                AspNetPager1.CurrentPageIndex = 1;
                AspNetPager2.CurrentPageIndex = AspNetPager1.CurrentPageIndex;
            }
        }

        protected void rptMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {   
                ((HyperLink)e.Item.FindControl("lnkMenu")).Text = ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).MenuName;
                ((HyperLink)e.Item.FindControl("lnkMenu")).NavigateUrl = "SciencTechExpansion.aspx?secondid="
                        + ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).ID.ToString()
                        + "&HaveChild=" + ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).HaveChild.ToString()
                        + "&name=" + ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).MenuName;
                if (((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).ID.ToString() == this.lblSecondid.Text.Trim())
                {
                    HtmlGenericControl divTitle = (HtmlGenericControl)e.Item.FindControl("divTitle");
                    divTitle.Attributes.Add("class", "Header_TitleCur1");
                }
            }
        }

        private void RepeaterDataBind()
        {
            IList<CJJCH.Model.T_NET_MenuSecond> list3 = new List<CJJCH.Model.T_NET_MenuSecond>();
            list3 = bll_second.GetMenuSecondList(0, 5);
            this.rptMenu.DataSource = list3;
            this.rptMenu.DataBind();

            int totalCount = 0;
            switch (this.lblMID.Text.Trim())
            {
                case "2":
                    IList<CJJCH.Model.T_NET_News> list = new List<CJJCH.Model.T_NET_News>();

                    list = bll_news.GetNewsList(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, Convert.ToInt32(this.lblSecondid.Text.Trim()), "", 0, "", "", ref totalCount, "");
                    AspNetPager1.RecordCount = totalCount;
                    AspNetPager2.RecordCount = totalCount;
                    this.rptNews.DataSource = list;
                    this.rptNews.DataBind();
                    break;
                case "5":
                    this.divCons.Style.Add("display", "");
                    this.divNews.Style.Add("display", "none");
                    IList<CJJCH.Model.T_NET_Consulting> list1 = new List<CJJCH.Model.T_NET_Consulting>();
                    list1 = bll_cons.GetConsultingList(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, Convert.ToInt32(this.lblSecondid.Text.Trim()), "", 0, "", "", ref totalCount, "");
                    AspNetPager1.RecordCount = totalCount;
                    AspNetPager2.RecordCount = totalCount;
                    this.rptCons.DataSource = list1;
                    this.rptCons.DataBind();
                    break;
                default:
                    break;
            }
            if (totalCount == 0)
                litMessage.Text = "<table width=100%><tr style=height:18px bgcolor=#FFFFFF><td align='center'><font color=red>对不起，系统没有检索出有关信息！<font></td></tr></table>";
            else
                litMessage.Text = "";

            AspNetPager1.CustomInfoHTML = "共有：<font color=\"blue\"><b>" + AspNetPager1.RecordCount.ToString() + "</b></font>条记录";
            AspNetPager1.CustomInfoHTML += " <font color=\"red\"><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font>";
            AspNetPager1.CustomInfoHTML += "/<font color=\"blue\"><b>" + AspNetPager1.PageCount.ToString() + "</b></font>";
            AspNetPager2.CustomInfoHTML = "共有：<font color=\"blue\"><b>" + AspNetPager1.RecordCount.ToString() + "</b></font>条记录";
            AspNetPager2.CustomInfoHTML += " <font color=\"red\"><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font>";
            AspNetPager2.CustomInfoHTML += "/<font color=\"blue\"><b>" + AspNetPager1.PageCount.ToString() + "</b></font>";
        }

        protected void rptNews_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                ((HyperLink)e.Item.FindControl("lnkTitle")).Text = LTP.Common.StringClass.GetENString(((CJJCH.Model.T_NET_News)e.Item.DataItem).DataTitle, 20);
                ((HyperLink)e.Item.FindControl("lnkTitle")).NavigateUrl = "SciencTechDetails.aspx?ID="
                    + LTP.Common.StringClass.EncodeUrl(((CJJCH.Model.T_NET_News)e.Item.DataItem).ID.ToString());
                ((Label)e.Item.FindControl("lblTime")).Text = ((CJJCH.Model.T_NET_News)e.Item.DataItem).PlusDate.ToString("yyyy/MM/dd");
            }
        }

        protected void rptCons_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                ((HyperLink)e.Item.FindControl("lnkTitle")).Text = LTP.Common.StringClass.GetENString(((CJJCH.Model.T_NET_Consulting)e.Item.DataItem).DataTitle, 20);
                ((HyperLink)e.Item.FindControl("lnkTitle")).NavigateUrl = "SciencTechDetails.aspx?ID="
                    + LTP.Common.StringClass.EncodeUrl(((CJJCH.Model.T_NET_Consulting)e.Item.DataItem).ID.ToString());
                ((Label)e.Item.FindControl("lblTime")).Text = ((CJJCH.Model.T_NET_Consulting)e.Item.DataItem).PlusDate.ToString("yyyy/MM/dd");
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            RepeaterDataBind();
            AspNetPager2.CurrentPageIndex = AspNetPager1.CurrentPageIndex;
        }
        protected void AspNetPager2_PageChanged(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = AspNetPager2.CurrentPageIndex;
        }
    }
}